cgo在linux平台调用so库,一直报错 您所在的位置:网站首页 go home原唱 cgo在linux平台调用so库,一直报错

cgo在linux平台调用so库,一直报错

#cgo在linux平台调用so库,一直报错| 来源: 网络整理| 查看: 265

用go的cgo在linux平台调用so库。因为这个so有关联性,所以一直调用不成功。

package main import ( "fftest/dylib" "fmt" "os" "runtime" "sync" ) // #cgo CFLAGS: -I./number // #cgo LDFLAGS: -L${SRCDIR} -lnumber var avformatDll *dylib.LazyDLL var avformatDllOnce sync.Once func main() { libPath, _ := os.Getwd() avformatPath := "" if runtime.GOOS == "linux" { os.Setenv("LD_LIBRARY_PATH", libPath+"/lib/linux") avformatPath = libPath + "/lib/linux/libavformat.so.58" } else { os.Setenv("LD_LIBRARY_PATH", libPath+"/lib/window") avformatPath = libPath + "/lib/window/avformat-58.dll" } fmt.Println("avformatPath=", avformatPath) avformatDllOnce.Do(func() { avformatDll = dylib.NewLazyDLL(avformatPath) }) //avformatDll.NewProc("") }

编译后avformatPath= /home/go/1/fftest/lib/linux/libavformat.sodlopen err: libavcodec.so.58: cannot open shared object file: No such file or directory会报这个错误。因为libavformat.so库涉及其他模块我感觉我的问题是要把so库所有关联的库都要链接起来。当时不知道怎么实现。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有